package com.song.tradition.page.details

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.song.tradition.entity.StoryData
import com.song.tradition.entity.personDataList
import com.song.tradition.page.components.CustomTitleTopAppBar
import com.song.tradition.ui.theme.customBgColor


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun PersonDetailScreen(
    navController: NavController,
    data: StoryData
) {

    Scaffold(
        topBar = {

            CustomTitleTopAppBar(title = data.name, navClick = {
                navController.popBackStack()
            })
        }
    ) {
        Surface(
            modifier = Modifier
                .fillMaxSize()
                .padding(paddingValues = it)
        ) {

            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .background(customBgColor)
                    .verticalScroll(rememberScrollState())
                    .padding(horizontal = 16.dp, vertical = 8.dp)
            ) {

                Row(
                    Modifier
                        .height(200.dp)
                        .fillMaxWidth()
                        .padding(8.dp), horizontalArrangement = Arrangement.Center,
                    verticalAlignment = Alignment.CenterVertically
                ) {

                    Card(
                        shape = CircleShape,
                        modifier = Modifier
                            .size(150.dp)
                            .padding(2.dp),
                        elevation = CardDefaults.cardElevation(2.dp),
                    ) {
                        Image(
                            painterResource(id = data.resId),
                            contentDescription = "",
                            modifier = Modifier.fillMaxSize(),
                            contentScale = ContentScale.Crop
                        )
                    }
                    Spacer(modifier = Modifier.width(8.dp))


                }

                Spacer(modifier = Modifier.height(16.dp))
                Text(text = "人物简介：", fontSize = 22.sp, fontWeight = FontWeight.Bold)
                Spacer(modifier = Modifier.height(16.dp))
                Text(
                    text = data.description,
                    lineHeight = 30.sp,
                    modifier = Modifier.fillMaxWidth()
                )

            }
        }
    }

}

@Preview
@Composable
fun PersonDetailScreenText() {
    PersonDetailScreen(
        navController = rememberNavController(
        ), data = personDataList[0]
    )
}